home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac-Source 1994 July
/
Mac-Source_July_1994.iso
/
Other Langs
/
Tickle-4.0 (tcl)
/
src
/
tar_dialog.c
< prev
next >
Wrap
Text File
|
1993-10-28
|
10KB
|
482 lines
#pragma segment TAR
/*
* Macintosh Tar
*
* The routines in this file deal with the dialogs presented to the user.
*
* Written by Craig Ruff.
*
* Note that the dialog dealing with directory selection is in dir.c.
*/
#include "tar.h"
#include <Resources.h>
#include <Events.h>
#include <SegLoad.h>
extern pascal Boolean UniversalFilter();
/*
* Dialog definitions
*/
#define aboutID 128 /* The "About ..." dialog */
#define okItem 1
#define blockID 129 /* The block size dialog */
#define sizeItem 3
#define typeID 131 /* Creator/Type dialog */
#define creatorItem 3
#define typeItem 4
/*
* Alert Definitions
*/
#define badBlockID 129 /* Block size incorrect alert */
#define osErrID 130 /* Generic OS Error alert */
#define pgmErrID 131 /* Program logic error alert */
#define hfsID 132 /* Must run under HFS alert */
#define askipID 133 /* Skipping archive file note */
#define stkErrID 134 /* Stack error alert */
#define dfID 135 /* Disk full alert */
/*
* AboutFilter - manage the "About ..." dialog
*
* Returns when the mouse or a key is pressed anywhere.
*/
pascal Boolean
AboutFilter(theDialog, theEvent, itemHit)
DialogPtr theDialog;
EventRecord *theEvent;
short *itemHit;
{
#pragma unused(theDialog)
switch (theEvent->what) {
case keyDown:
case mouseDown:
*itemHit = 1;
return(true);
break;
default:
return(false);
break;
}
}
/*
* DoAboutBox - put the "About ..." dialog on the screen
*/
DoAboutBox() {
short itemHit, itemType;
WindowPtr myWindow;
GrafPtr thePort;
PenState pn;
Rect okBox;
Handle okHdl;
GetPort(&thePort);
myWindow = GetNewDialog(aboutID, nil, (WindowPtr) -1);
GetDItem(myWindow, okItem, &itemType, &okHdl, &okBox);
SetPort(myWindow);
InsetRect(&okBox, -4, -4);
GetPenState(&pn);
PenSize(3, 3);
FrameRoundRect(&okBox, 16, 16);
SetPenState(&pn);
do {
ModalDialog(UniversalFilter/*AboutFilter*/, &itemHit);
} while (itemHit != 1);
DisposDialog(myWindow);
SetPort(thePort);
}
/*
* ValidBlockSize - checks the user entered blocksize for validity.
*
* Returns true if ok, false if bad.
*/
Boolean
ValidBlockSize(theDialog)
DialogPtr theDialog;
{
long n;
short type;
Handle hdl;
Rect box;
char text[256];
GetDItem(theDialog, sizeItem, &type, &hdl, &box);
GetIText(hdl, text);
StringToNum(text, &n);
/*
* These limits are somewhat arbitrary.
*/
if ((n < 1) || (n > 128))
{
NoteAlert(badBlockID, UniversalFilter);
SelIText(theDialog, sizeItem, 0, 32767);
return(false);
}
blocking = (int) n;
blockSize = blocking * RECORDSIZE;
return(true);
}
Rect okBox; /* ok Box location (gotten once for speed) */
ControlHandle okHdl; /* ok Box handle */
/*
* BlockFilter - manage user events during the block size dialog
*
* Allows numeric entry and editing, validates size.
* Returns true if the dialog should exit, false to continue.
*/
pascal Boolean
BlockFilter(theDialog, theEvent, itemHit)
DialogPtr theDialog;
EventRecord *theEvent;
short *itemHit;
{
long t;
Point lpt;
GrafPtr savedPort;
switch (theEvent->what) {
case keyDown:
switch ((char) (theEvent->message & charCodeMask)) {
case RETURN:
case ENTER:
goto validate;
break;
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
case TAB: case BS:
break;
default:
SysBeep(5);
theEvent->what = nullEvent;
break;
}
break;
case mouseDown:
lpt = theEvent->where;
GetPort(&savedPort);
SetPort((GrafPtr) theDialog);
GlobalToLocal(&lpt);
SetPort(savedPort);
if (PtInRect(lpt, &okBox)) {
validate: if (ValidBlockSize(theDialog)) {
*itemHit = ok;
HiliteControl(okHdl, 1);
Delay(8L, &t);
HiliteControl(okHdl, 0);
return(true);
} else
theEvent->what = nullEvent;
}
break;
/*
** WARNING: These are taken from tickle.h!!!
*/
#define wUpdate 1
#define wActivate 3
case updateEvt:
wind_parse((WindowPtr) theEvent->message, theEvent, wUpdate);
break;
case activateEvt:
wind_parse((WindowPtr) theEvent->message, theEvent, wActivate);
break;
}
return(false);
}
/*
* CreatorTypeFilter - manage user events during the Creator/Type dialog
*
*/
pascal Boolean
CreatorTypeFilter(theDialog, theEvent, itemHit)
DialogPtr theDialog;
EventRecord *theEvent;
short *itemHit;
{
short type;
Handle hdl;
Rect box;
char text[256];
int n;
long t;
Point lpt;
GrafPtr savedPort;
switch (theEvent->what) {
case keyDown:
switch ((char) (theEvent->message & charCodeMask)) {
case RETURN:
case ENTER:
goto done;
break;
default:
break;
}
break;
case mouseDown:
lpt = theEvent->where;
GetPort(&savedPort);
SetPort((GrafPtr) theDialog);
GlobalToLocal(&lpt);
SetPort(savedPort);
if (PtInRect(lpt, &okBox)) {
done:
GetDItem(theDialog, creatorItem, &type, &hdl, &box);
GetIText(hdl, text);
n = (unsigned char) text[0];
if (n > 4)
n = 4;
strncpy(fdCreator, &text[1], n);
GetDItem(theDialog, typeItem, &type, &hdl, &box);
GetIText(hdl, text);
n = (unsigned char) text[0];
if (n > 4)
n = 4;
strncpy(fdType, &text[1], n);
*itemHit = ok;
HiliteControl(okHdl, 1);
Delay(8L, &t);
HiliteControl(okHdl, 0);
return(true);
}
break;
case updateEvt:
wind_parse((WindowPtr) theEvent->message, theEvent, wUpdate);
break;
case activateEvt:
wind_parse((WindowPtr) theEvent->message, theEvent, wActivate);
break;
}
return(false);
}
/*
* DoBlockSize - put the block size dialog on the screen
*
* Puts the current block size into the edit field.
*/
DoBlockSize()
{
short itemHit;
DialogPtr theDialog;
Handle hdl;
short type;
Rect box;
char text[256];
PenState pn;
GrafPtr thePort;
GetPort(&thePort);
theDialog = GetNewDialog(blockID, nil, (WindowPtr) -1);
GetDItem(theDialog, sizeItem, &type, &hdl, &box);
NumToString((long) blocking, text);
SetIText(hdl, text);
SelIText(theDialog, sizeItem, 0, 32767);
GetDItem(theDialog, ok, &type, (Handle *) &okHdl, &okBox);
SetPort(theDialog);
InsetRect(&okBox, -4, -4);
GetPenState(&pn);
PenSize(3, 3);
FrameRoundRect(&okBox, 16, 16);
SetPenState(&pn);
do {
ModalDialog(BlockFilter, &itemHit);
} while ((itemHit != ok) && (itemHit != cancel));
DisposDialog(theDialog);
SetPort(thePort);
}
/*
* DoCreatorType - put the set Creator/Type dialog on the screen
*
* Puts the current Creator and Type into the edit field.
*/
DoCreatorType()
{
short itemHit, saveref;
DialogPtr theDialog;
char text[256], buffer[16];
GrafPtr thePort;
extern short app_refnum;
extern char fdCreator[]; /* Finder Creator */
extern char fdType[]; /* Finder Type */
GetPort(&thePort);
theDialog = GetNewDialog(typeID, NULL, (WindowPtr) -1);
sprintf(text, "%4.4s", fdCreator);
MySetText(theDialog, creatorItem, text);
sprintf(text, "%4.4s", fdType);
MySetText(theDialog, typeItem, text);
SelIText(theDialog, (short)typeItem, (short)0, (short)256);
do {
SetPort(theDialog);
FrameButton(theDialog, ok);
ModalDialog((ModalFilterProcPtr)UniversalFilter, &itemHit);
} while ((itemHit != ok) && (itemHit != cancel));
if (itemHit == ok) {
saveref = CurResFile();
UseResFile(app_refnum);
MyGetText(theDialog, creatorItem, text);
sprintf(buffer, "%4.4s", text);
memcpy(fdCreator, buffer, 4);
MyGetText(theDialog, typeItem, text);
sprintf(buffer, "%4.4s", text);
memcpy(fdType, buffer, 4);
sprintf(buffer, "%4.4s%4.4s", fdCreator, fdType);
SaveData('ftyp', 0, "\pTAR", buffer, 8);
UseResFile(saveref);
}
DisposDialog(theDialog);
SetPort(thePort);
}
/*
** OSAlert - put a generic OS Error Alert on the screen
**
** Used for errors not handled in another way (yet).
*/
OSAlert(p0, p1, p2, err)
char *p0, *p1, *p2;
OSErr err;
{
char buf[256];
if (tar_scripting)
{
Tcl_AppendResult(tar_interp, " OS Error \"", Tcl_MacGetError(tar_interp, err),
"\" ", (char *) NULL);
return;
}
/*
** Manage the contingency of being called for resources missing!
*/
if (GetResource('ALRT', osErrID) == NULL)
{
GrafPtr wmPort;
long t;
Rect r;
GetWMgrPort(&wmPort);
SetPort(wmPort);
SetRect(&r, 140, 150, 360, 180);
EraseRect(&r);
MoveTo(150,170);
DrawString("\pPANIC! Resources Missing!");
Delay(600L, &t);
ExitToShell();
}
NumToString((long) err, buf);
ParamText(p0, p1, p2, buf);
StopAlert(osErrID, UniversalFilter);
}
/*
** PgmAlert - put a program logic alert on the screen
*/
PgmAlert(p0, p1, p2)
char *p0, *p1, *p2;
{
if (tar_scripting)
{
if (p0) p2cstr(p0);
if (p1) p2cstr(p1);
if (p2) p2cstr(p2);
Tcl_AppendResult(tar_interp, " ", p0, " ", p1, " ", p2,
" ", (char *) NULL);
if (p0) c2pstr(p0);
if (p1) c2pstr(p1);
if (p2) c2pstr(p2);
return;
}
ParamText(p0, p1, p2, nil);
StopAlert(pgmErrID, UniversalFilter);
}
/*
* HFSAlert - put a "HFS only" alert on the screen
*/
HFSAlert()
{
if (tar_scripting)
{
Tcl_AppendResult(tar_interp, " only allowed for HFS Macintoshes ", (char *) NULL);
return;
}
StopAlert(hfsID, UniversalFilter);
}
/*
* DFAlert - Oops, disk is full
*/
DFAlert()
{
if (tar_scripting)
{
Tcl_AppendResult(tar_interp, " disk is full ", (char *) NULL);
return;
}
StopAlert(dfID, UniversalFilter);
}
/*
* ArSkipAlert - put a "skipping archive file" note on the screen
*/
ArSkipAlert()
{
if (tar_scripting)
{
Tcl_AppendResult(tar_interp, " skipping archive file ", (char *) NULL);
return;
}
NoteAlert(askipID, UniversalFilter);
}
/*
* StkErrAlert - put a stack corrupted alert on the screen
*/
StkErrAlert()
{
StopAlert(stkErrID, UniversalFilter);
ExitToShell();
}